package com.matei.eece411.A2;

import java.rmi.*;
import java.rmi.server.*;

public class MessageCallbackImpl extends UnicastRemoteObject implements MessageCallback {

	private javax.swing.JTextArea textArea;
	private String name;

    public MessageCallbackImpl(javax.swing.JTextArea ta) throws RemoteException {
    	    textArea = ta;
    }
    
    public void joinMessage(String name) throws RemoteException
    {
        try {
    	    textArea.append(name + " has joined the chat room.\n");
    	}
        catch(Exception e){
            System.out.println("Message Failure");
            e.printStackTrace();
        };
    }
    
    public void sendMessage(String name, String message) throws RemoteException
    {
        try {
    	    textArea.append(name + " says: " + message + "\n");
    	}
        catch(Exception e){
            System.out.println("Message Failure");
            e.printStackTrace();
        };
    }
    
    public void exitMessage(String name) throws RemoteException {
        try {
    	    textArea.append(name + " has left the chat room.\n");
    	}
        catch(Exception e){
            System.out.println("Message Failure");
        };
    }
    
    public void setName(String name) {
    	this.name = name;
    }
    
    public String getName() {
    	return name;
    }
}